/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eproject_sem2;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author ZER0
 */
@SuppressWarnings("serial")
public class Create_Account extends javax.swing.JFrame {

    Create_account_Sever s = new Create_account_Sever();
    VotesSent_Sever a = new VotesSent_Sever();
    ListOfPrice_Sever a1 = new ListOfPrice_Sever();

    public JInternalFrame getItnfCreateAccount() {
        return itnfCreateAccount;
    }
    

    /**
     * Creates new form Create_Account
     */
    public Create_Account() {
        initComponents();
        tfUserID.setText(a.CreateID("Users", "NH"));
        tfUserID.setEditable(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        itnfCreateAccount = new javax.swing.JInternalFrame();
        jpRegister = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbUser = new javax.swing.JTable();
        jpIAccount = new javax.swing.JPanel();
        lbEployeeID = new javax.swing.JLabel();
        tfEmployeeID = new javax.swing.JTextField();
        lbUserID = new javax.swing.JLabel();
        tfUserID = new javax.swing.JTextField();
        lbUserName = new javax.swing.JLabel();
        lbPassword = new javax.swing.JLabel();
        tfUserName = new javax.swing.JTextField();
        btRegister = new javax.swing.JButton();
        pfPassword = new javax.swing.JPasswordField();
        btReset = new javax.swing.JButton();
        btCancelR = new javax.swing.JButton();
        pfPassAgain = new javax.swing.JPasswordField();
        lbPassAgain = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        itnfCreateAccount.setClosable(true);
        itnfCreateAccount.setVisible(true);

        jpRegister.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Register", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14))); // NOI18N

        tbUser.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "EmployeeID", "UserID", "Username"
            }
        ));
        jScrollPane1.setViewportView(tbUser);

        jpIAccount.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Information Account", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        lbEployeeID.setText("EmployeeID:");

        lbUserID.setText("UserID:");

        lbUserName.setText("User name:");

        lbPassword.setText("Password:");

        tfUserName.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tfUserNameKeyReleased(evt);
            }
        });

        btRegister.setText("Register");
        btRegister.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRegisterActionPerformed(evt);
            }
        });

        pfPassword.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                pfPasswordKeyReleased(evt);
            }
        });

        btReset.setText("Reset");
        btReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btResetActionPerformed(evt);
            }
        });

        btCancelR.setText("Cancel");
        btCancelR.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelRActionPerformed(evt);
            }
        });

        pfPassAgain.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pfPassAgainActionPerformed(evt);
            }
        });
        pfPassAgain.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                pfPassAgainKeyReleased(evt);
            }
        });

        lbPassAgain.setText(" E Password :");

        javax.swing.GroupLayout jpIAccountLayout = new javax.swing.GroupLayout(jpIAccount);
        jpIAccount.setLayout(jpIAccountLayout);
        jpIAccountLayout.setHorizontalGroup(
            jpIAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpIAccountLayout.createSequentialGroup()
                .addContainerGap(147, Short.MAX_VALUE)
                .addGroup(jpIAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpIAccountLayout.createSequentialGroup()
                        .addGroup(jpIAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lbUserID)
                            .addComponent(lbEployeeID)
                            .addComponent(lbUserName)
                            .addComponent(lbPassword)
                            .addComponent(lbPassAgain))
                        .addGap(18, 18, 18)
                        .addGroup(jpIAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(pfPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(pfPassAgain, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tfUserName, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tfUserID, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tfEmployeeID, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jpIAccountLayout.createSequentialGroup()
                        .addGap(126, 126, 126)
                        .addComponent(btRegister)
                        .addGap(26, 26, 26)
                        .addComponent(btReset, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btCancelR)))
                .addGap(155, 155, 155))
        );
        jpIAccountLayout.setVerticalGroup(
            jpIAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpIAccountLayout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(jpIAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbEployeeID)
                    .addComponent(tfEmployeeID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpIAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbUserID)
                    .addComponent(tfUserID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(jpIAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbUserName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpIAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(pfPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbPassword))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpIAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(pfPassAgain, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbPassAgain))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                .addGroup(jpIAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btRegister)
                    .addComponent(btReset)
                    .addComponent(btCancelR))
                .addGap(31, 31, 31))
        );

        javax.swing.GroupLayout jpRegisterLayout = new javax.swing.GroupLayout(jpRegister);
        jpRegister.setLayout(jpRegisterLayout);
        jpRegisterLayout.setHorizontalGroup(
            jpRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
            .addComponent(jpIAccount, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jpRegisterLayout.setVerticalGroup(
            jpRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpRegisterLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpIAccount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout itnfCreateAccountLayout = new javax.swing.GroupLayout(itnfCreateAccount.getContentPane());
        itnfCreateAccount.getContentPane().setLayout(itnfCreateAccountLayout);
        itnfCreateAccountLayout.setHorizontalGroup(
            itnfCreateAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpRegister, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        itnfCreateAccountLayout.setVerticalGroup(
            itnfCreateAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpRegister, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(itnfCreateAccount)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(itnfCreateAccount)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    @SuppressWarnings("deprecation")
    private void btRegisterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRegisterActionPerformed
        try {
            // TODO add your handling code here:
            String Pass = MH_MD5.MD5(pfPassword.getText());
            System.out.println(Pass);
            if (pfPassword.getText() == null ? pfPassAgain.getText() == null : pfPassword.getText().equalsIgnoreCase(pfPassAgain.getText())) {
                s.InsertAccount(tfUserID.getText(), tfEmployeeID.getText(), tfUserName.getText(), Pass, "Users", "UserID", "EmployeeID", "Username", "Password");
                s.ShowTable(tfUserID.getText(), tfEmployeeID.getText(), tfUserName.getText(), tbUser, "UserID", "EmployeeID", "Username");
            } else {
                JOptionPane.showMessageDialog(rootPane, "Passwords do not match");
            }
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(Create_Account.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(Create_Account.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btRegisterActionPerformed

    private void btResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btResetActionPerformed
        // TODO add your handling code here:
        tfEmployeeID.setText(null);
        tfUserID.setText(null);
        tfUserName.setText(null);
        pfPassword.setText(null);
        pfPassAgain.setText(null);
        tfUserID.setText(a.CreateID("Users", "NH"));
        s.ShowTable(null, null, null, tbUser, "UserID", "EmployeeID", "Username");
    }//GEN-LAST:event_btResetActionPerformed

    private void btCancelRActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelRActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_btCancelRActionPerformed

    private void tfUserNameKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfUserNameKeyReleased
        // TODO add your handling code here:
        tfUserName.setText(tfUserName.getText().replaceAll("[!@#$%^&*()=+]", "You can not enter special characters"));
    }//GEN-LAST:event_tfUserNameKeyReleased

    private void pfPasswordKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_pfPasswordKeyReleased
        // TODO add your handling code here:
        pfPassword.setText(pfPassword.getText().replaceAll("[!@#$%^&*()=+]", ""));
    }//GEN-LAST:event_pfPasswordKeyReleased

    private void pfPassAgainKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_pfPassAgainKeyReleased
        // TODO add your handling code here:
        pfPassAgain.setText(pfPassAgain.getText().replaceAll("[!@#$%^&*()=+]", ""));
    }//GEN-LAST:event_pfPassAgainKeyReleased

    private void pfPassAgainActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pfPassAgainActionPerformed
        try {
            // TODO add your handling code here:
            String Pass = MH_MD5.MD5(pfPassword.getText());
            if (pfPassword.getText() == null ? pfPassAgain.getText() == null : pfPassword.getText().equalsIgnoreCase(pfPassAgain.getText())) {
                s.InsertAccount(tfUserID.getText(), tfEmployeeID.getText(), tfUserName.getText(), Pass, "Users", "UserID", "EmployeeID", "Username", "Password");
                s.ShowTable(tfUserID.getText(), tfEmployeeID.getText(), tfUserName.getText(), tbUser, "UserID", "EmployeeID", "Username");
            } else {
                JOptionPane.showMessageDialog(rootPane, "Passwords do not match");
            }
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(Create_Account.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(Create_Account.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_pfPassAgainActionPerformed
//asd
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCancelR;
    private javax.swing.JButton btRegister;
    private javax.swing.JButton btReset;
    private javax.swing.JInternalFrame itnfCreateAccount;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel jpIAccount;
    private javax.swing.JPanel jpRegister;
    private javax.swing.JLabel lbEployeeID;
    private javax.swing.JLabel lbPassAgain;
    private javax.swing.JLabel lbPassword;
    private javax.swing.JLabel lbUserID;
    private javax.swing.JLabel lbUserName;
    private javax.swing.JPasswordField pfPassAgain;
    private javax.swing.JPasswordField pfPassword;
    private javax.swing.JTable tbUser;
    private javax.swing.JTextField tfEmployeeID;
    private javax.swing.JTextField tfUserID;
    private javax.swing.JTextField tfUserName;
    // End of variables declaration//GEN-END:variables
}
